package com.example.oasystem.controller.process;

import com.example.oasystem.entity.dept.AoaDept;
import com.example.oasystem.entity.page.Page;
import com.example.oasystem.entity.process.*;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.type.AoaTypeList;
import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.service.AoaProcessListdServiceOfl;
import com.example.oasystem.service.AoaStatusListService;
import com.example.oasystem.service.AoaTypeListService;
import com.example.oasystem.utils.ConvertUpMoneyUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AoaProcessListdControllerOfl {

    @Autowired
    AoaProcessListdServiceOfl aoaProcessListdServiceOfl;

    @Autowired
    AoaStatusListService aoaStatusListService;

    @Autowired
    AoaTypeListService aoaTypeListService;

        @RequestMapping("/flowmanage")
        public String flowmanage(Model model , HttpServletRequest request,
                                    @RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                    @RequestParam(value = "pageSize",defaultValue = "2") int pageSize,
                                    @RequestParam(value = "baseKey",defaultValue = "")String baseKey){
            AoaUser user = (AoaUser) request.getSession().getAttribute("user");
            Long processUserId = user.getUserId();

    //        List<AoaProcessListOfl> aoaProcessListOfls = aoaProcessListdServiceOfl.aoaProcessList(processUserId);
            PageInfo<AoaProcessListOfl> pageInfo = aoaProcessListdServiceOfl.aoaProcessListPaginationSearch(processUserId, baseKey, pageNum, pageSize);

            Page page = new Page(pageInfo.getSize(),Math.toIntExact(pageInfo.getTotal()),pageInfo.getPages(),pageInfo.getPageNum(),pageInfo.isIsFirstPage(),pageInfo.isIsLastPage());

            List<AoaProcessListOfl> list = pageInfo.getList();

            List<AoaTypeList> aoaTypeLists = aoaTypeListService.aoaTypeLists();

            List<AoaStatusList> aoaStatusLists = aoaStatusListService.aoaStatusLists();

            model.addAttribute("page",page);

            model.addAttribute("prolist",list);

            model.addAttribute("typename",aoaTypeLists);
            model.addAttribute("baseKey",baseKey);
            model.addAttribute("statusname",aoaStatusLists);

            model.addAttribute("url","flowmanagePaging");
            return "/process/flowmanage";
        }
        @RequestMapping("/flowmanagePaging")
        public String flowmanagePaging(Model model , HttpServletRequest request,
                                 @RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                 @RequestParam(value = "pageSize",defaultValue = "2") int pageSize,
                                 @RequestParam(value = "baseKey",defaultValue = "")String baseKey){
            AoaUser user = (AoaUser) request.getSession().getAttribute("user");
            Long processUserId = user.getUserId();

    //      List<AoaProcessListOfl> aoaProcessListOfls = aoaProcessListdServiceOfl.aoaProcessList(processUserId);
            PageInfo<AoaProcessListOfl> pageInfo = aoaProcessListdServiceOfl.aoaProcessListPaginationSearch(processUserId, baseKey, pageNum, pageSize);

            Page page = new Page(pageInfo.getSize(),Math.toIntExact(pageInfo.getTotal()),pageInfo.getPages(),pageInfo.getPageNum(),pageInfo.isIsFirstPage(),pageInfo.isIsLastPage());

            List<AoaProcessListOfl> list = pageInfo.getList();

            List<AoaTypeList> aoaTypeLists = aoaTypeListService.aoaTypeLists();

            List<AoaStatusList> aoaStatusLists = aoaStatusListService.aoaStatusLists();

            model.addAttribute("page",page);

            model.addAttribute("prolist",list);

            model.addAttribute("typename",aoaTypeLists);
            model.addAttribute("baseKey",baseKey);
            model.addAttribute("statusname",aoaStatusLists);

            model.addAttribute("url","flowmanagePaging");
            return "/process/managetable";
        }

}
